//
//  FKChooseAttrFooterView.m
//  WanTao
//
//  Created by Macbook Pro on 2019/3/27.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKChooseAttrFooterView.h"
#import <PPNumberButton.h>

@interface FKChooseAttrFooterView ()<PPNumberButtonDelegate>

@end

@implementation FKChooseAttrFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        [self setupSubviews];
    }
    return self;
}

- (void)setupSubviews
{
    self.clipsToBounds = true;
    
    UIView *separator = [UIView fk_lineWithFrame:CGRectMake(12, 0, fkScreenW - 24, 0.8)];
    [self addSubview:separator];
    
    UILabel *numTitle = [UILabel fk_labelWithFont:fk_adjustFont(14) textColor:fkColor999999 text:@"数量"];
    [self addSubview:numTitle];
    
    UIView *container = [[UIView alloc] init];
    [self addSubview:container];
    [container fk_viewCornerRadius:0 borderWidth:0.8 borderColor:[UIColor groupTableViewBackgroundColor]];
    
    PPNumberButton *numberButton = [PPNumberButton numberButtonWithFrame:CGRectZero];
    [container addSubview:numberButton];
    numberButton.currentNumber = 1;
    numberButton.editing = NO;
    // 设置最小值
    numberButton.minValue = 1;
    // 设置最大值
    numberButton.maxValue = 1000;
    // 设置输入框中的字体大小
    numberButton.inputFieldFont = 15;
    numberButton.increaseTitle = @"＋";
    numberButton.decreaseTitle = @"－";
    //        numberButton.increaseBgColor = fkBgColor;
    //        numberButton.decreaseBgColor = fkBgColor;
    numberButton.delegate = self;
    numberButton.longPressSpaceTime = CGFLOAT_MAX;
    
    [numTitle mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(12);
        make.centerY.offset(0);
    }];
    [container mas_makeConstraints:^(MASConstraintMaker *make) {
        //            make.right.offset(-15);
        make.right.offset(-12);
        make.centerY.equalTo(numTitle);
        make.size.mas_equalTo(CGSizeMake(fk_adjustW(100), fk_adjustW(32)));
    }];
    [numberButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.offset(0);
    }];
}


#pragma mark - PPNumberButtonDelegate
- (void)pp_numberButton:(PPNumberButton *)numberButton number:(NSInteger)number increaseStatus:(BOOL)increaseStatus
{
    if (number > [self.storeCount integerValue]) {
        [SVProgressHUD showInfoWithStatus:@"库存不足!"];
        numberButton.currentNumber = [self.storeCount integerValue];
    }
    
    if (self.buyNumUpdateBlock) {
        self.buyNumUpdateBlock(numberButton.currentNumber);
    }
}

//- (void)setData:(id)data
//{
//    [super setData:data];
//
//    self.storeCount = data;
//}


@end
